package question

//2319. 判断矩阵是否是一个 X 矩阵
func checkXMatrix(grid [][]int) bool {
	m := len(grid)
	if m < 3 {
		return false
	}
	n := len(grid[0])
	if m != n {
		return false
	}
	x1, y1 := 0, 0
	x2, y2 := 0, m-1
	x3, y3 := n-1, 0
	x4, y4 := n-1, m-1
	for y1 <= y2 {
		if grid[x1][y1] > 0 && grid[x2][y2] > 0 && grid[x3][y3] > 0 && grid[x4][y4] > 0 {
			grid[x1][y1] = 0
			grid[x2][y2] = 0
			grid[x3][y3] = 0
			grid[x4][y4] = 0
			x1++
			y1++
			x2++
			y2--
			x3--
			y3++
			x4--
			y4--
		} else {
			return false
		}
	}
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if grid[i][j] > 0 {
				return false
			}
		}
	}
	return true
}
